package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:problemMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/6/13 17:41
 * @Version 1.0
 */
@Mapper
public interface problemMapp {
    //修改问题
    @DS("baodingRussia")
    @Select("update problem set " +
            "workshop=#{workshop}," +
            "drawing=#{drawing}," +
            "op=#{op}," +
            "liability=#{liability}," +
            "liabilityNub=#{liabilityNub}," +
            "occurDate=#{occurDate}," +
            "quantity=#{quantity}," +
            "problemName=#{problemName}," +
            "describeUse=#{describeUse}," +
            "type1=#{type1}," +
            "type2=#{type2} where idUse=#{idUse}")
    void problemAddEdit(problemPojo problemPojo);

    @DS("baodingRussia")
    @Insert("INSERT INTO problem (workshop, drawing, op, occurDate, noteTaker, liability, liabilityNub, problemName, describeUse, quantity, introspection, statusUse, origin, outflow, correct, temporaryUse, permanent, switchDate, switchNumber, correctDate, correctLiability, correctOut, correctResult, correctValidate, temporaryValidate, temporaryResult, temporaryDate, temporaryLiability, temporaryOut, permanentDate, permanentLiability, permanentOut, permanentResult, permanentValidate, introspectionDate, introspectionLiability, introspectionOut, introspectionResult, introspectionValidate,finish, report, type1, type2, establishTime, UpdateTime) " +
            "VALUES (#{workshop}, #{drawing}, #{op}, #{occurDate}, #{noteTaker}, #{liability}, #{liabilityNub}, #{problemName}, #{describeUse}, #{quantity}, #{introspection}, #{statusUse}, #{origin}, #{outflow}, #{correct}, #{temporaryUse}, #{permanent}, #{switchDate}, #{switchNumber}, #{correctDate}, #{correctLiability}, #{correctOut}, #{correctResult}, #{correctValidate}, #{temporaryValidate}, #{temporaryResult}, #{temporaryDate}, #{temporaryLiability}, #{temporaryOut}, #{permanentDate}, #{permanentLiability}, #{permanentOut}, #{permanentResult}, #{permanentValidate}, #{introspectionDate}, #{introspectionLiability}, #{introspectionOut}, #{introspectionResult}, #{introspectionValidate},#{finish},#{report},#{type1},#{type2}, #{establishTime}, #{UpdateTime})")
    void insertOne(problemPojo problemPojo);
    //加载时，查询所有的问题
    @DS("baodingRussia")
    @Select("select * from problem")
    List<problemPojo> problemAllList();
    //根据ID，向数据库中写入代码(文本类）。
    @DS("baodingRussia")
    @Select("update problem set ${field}=#{val} where idUse=#{idUse}")
    void upDataField(Integer idUse, String field, String val);
    //根据ID，向数据库中写入代码(数字类）。
    @DS("baodingRussia")
    @Select("update problem set ${field}=#{val},UpdateTime=#{uptime} where idUse=#{idUse}")
    void upDataFieldNmb(Integer idUse, String field, Integer val, LocalDateTime uptime);
    //用户要查找需要汇报的项目
    @DS("baodingRussia")
    @Select("select * from problem where report='是'")
    List<problemPojo> problemAllListType1();

    //按照录入日期查询根据不同的条件，有是不是我自己的，是不是未结题的，然后是那天录入的，现在查询的都是我自己的
    @DS("baodingRussia")
    @Select("select * from problem where liabilityNub like concat('%',#{isMy},'%') and finish=#{isEnd} and date_format(establishTime,'%Y-%m-%d')=#{isDate}")
    List<problemPojo> problemInputDateQueryIsMy(String isMy, String isEnd, String isDate);
    //查找我自己下所有的项目
    @DS("baodingRussia")
    @Select("select * from problem where liabilityNub like concat('%',#{isMy},'%') and date_format(establishTime,'%Y-%m-%d')=#{isDate}")
    List<problemPojo> problemInputDateQueryIsMyAll(String isMy, String isDate);
    //修改一个字段内容，并且把修改时间改掉
    @DS("baodingRussia")
    @Update("update problem set ${fieldName}=#{val},UpdateTime=#{uptime} where idUse=#{id}")

    void upDataOneField(Integer id, String fieldName, String val, LocalDateTime uptime);
    //按照录入日期筛选，全部的，区别为是否结题
    @DS("baodingRussia")
    @Select("select * from problem where finish=#{isEnd} and date_format(establishTime,'%Y-%m-%d')=#{isDate}")
    List<problemPojo> problemInputDateQueryAll(String isEnd, String isDate);
    //按照录入日期筛选，全部问题
    @DS("baodingRussia")
    @Select("select * from problem where date_format(establishTime,'%Y-%m-%d')=#{isDate}")
    List<problemPojo> problemInputDateQueryIsDate(String isDate);
    //从新问题库中，查询某一个字段，等于多个值的数据(是查询字符串）
    @DS("newMscLowCodeFormal")
    @Select("select * from problem_data where (${filedName}=#{firstFiledVal} or ${filedName}=#{secondFiledVal} or ${filedName}=#{threeFiledVal} or ${filedName}=#{fourthFiledVal} or ${filedName}=#{fifthFiledVal})  and deleteSign=1")
    List<problemDataPojo> inquiryProblemOneFindSeveralVal(String filedName, String firstFiledVal, String secondFiledVal, String threeFiledVal, String fourthFiledVal, String fifthFiledVal);
    //修改新问题库中的某一行，修改所有的字段
    @DS("newMscLowCodeFormal")
    @Update("UPDATE problem_data SET " +
            "establishTime=#{establishTime}, " +
            "updateTime=#{updateTime}, " +
            "deleteSign=#{deleteSign}, " +
            "editName=#{editName}, " +
            "workshop=#{workshop}, " +
            "lineName=#{lineName}, " +
            "drawing=#{drawing}, " +
            "op=#{op}, " +
            "occurDate=#{occurDate}, " +
            "noteTaker=#{noteTaker}, " +
            "liability=#{liability}, " +
            "liabilityNub=#{liabilityNub}, " +
            "problemName=#{problemName}, " +
            "describeUse=#{describeUse}, " +
            "describeAnnex=#{describeAnnex}, " +
            "quantity=#{quantity}, " +
            "introspection=#{introspection}, " +
            "statusUse=#{statusUse}, " +
            "origin=#{origin}, " +
            "outflow=#{outflow}, " +
            "temporaryUse=#{temporaryUse}, " +
            "correct=#{correct}, " +
            "switchDate=#{switchDate}, " +
            "switchNumber=#{switchNumber}, " +
            "correctDate=#{correctDate}, " +
            "temporaryDate=#{temporaryDate}, " +
            "temporaryLiability=#{temporaryLiability}, " +
            "permanentDate=#{permanentDate}, " +
            "permanentLiability=#{permanentLiability}, " +
            "introspectionDate=#{introspectionDate}, " +
            "introspectionLiability=#{introspectionLiability}, " +
            "conclusion=#{conclusion}, " +
            "finish=#{finish}, " +
            "report=#{report}, " +
            "type1=#{type1}, " +
            "correctOut=#{correctOut}, " +
            "type2=#{type2}, " +
            "machinePlateName=#{machinePlateName}, " +
            "machinePlateId=#{machinePlateId}, " +
            "peoplePlateName=#{peoplePlateName}, " +
            "peoplePlateId=#{peoplePlateId}, " +
            "materialPlateName=#{materialPlateName}, " +
            "materialPlateId=#{materialPlateId}, " +
            "methodPlateName=#{methodPlateName}, " +
            "methodPlateId=#{methodPlateId}, " +
            "environmentPlateName=#{environmentPlateName}, " +
            "environmentPlateId=#{environmentPlateId}, " +
            "measurePlateName=#{measurePlateName}, " +
            "measurePlateId=#{measurePlateId}, " +
            "correctLiability=#{correctLiability}, " +
            "permanent=#{permanent}, " +
            "writeName=#{writeName}, " +
            "examineName=#{examineName}, " +
            "approveName=#{approveName}, " +
            "liabilityName=#{liabilityName}, " +
            "isIndemnify=#{isIndemnify}, " +
            "isEndIndemnify=#{isEndIndemnify}, " +
            "supplierName=#{supplierName}, " +
            "isExam=#{isExam}, " +
            "saleDate=#{saleDate}, " +
            "mileage=#{mileage}," +
            "partName=#{partName}"+
            " WHERE id=#{id}")
    void editOneAll(problemDataPojo pojo);
    //批量对问题索赔单的数据进行插入
    @DS("newMscLowCodeFormal")
    void insertWarrantyList(List<warrantyClaimsPojo> warrantyClaimsPojoList);
    //查询出所有的索赔信息
    @DS("newMscLowCodeFormal")
    @Select("select * from warranty_claims where deleteSign=1")
    List<warrantyClaimsPojo> inquiryWarrantyClaimAll();
    //辅助函数，对售后索赔单的字段进行修改，根据id，修改多个字段，字段名称需要按照‘/’隔开，val也是一样的，并且需要和字段对应
    @DS("newMscLowCodeFormal")
    @Update("update warranty_claims set ${filedName}=#{filedVal} where id=#{id}")
    void editWarrantyClaimOneField(int id,String filedName, String filedVal);
    //辅助函数，根据id，向后端进行筛选问题库所有的数据
    @DS("newMscLowCodeFormal")
    @Select("SELECT * FROM problem_data WHERE id=#{id} and deleteSign=1 LIMIT 1")
    problemDataPojo inquiryProblemById(Integer id);
    //辅助函数，在索赔单中，查询出所有的IPTV问题，通过一个IPTV类型，找到所有不为空的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from warranty_claims where ${filedName} IS NOT NULL AND TRIM(${filedName}) != '' and TRIM(${filedName}) != '-' and deleteSign=1")
    List<warrantyClaimsPojo> inquiryWarrantyClaimOneFiledNoVoid(String filedName);
    //在索赔列表中，查询一个字段等于某一个值
    @DS("newMscLowCodeFormal")
    @Select("select * from warranty_claims where deleteSign=1 and ${filedName}=#{s}")
    List<warrantyClaimsPojo> inquiryWarrantyClaimOneFiled(String filedName, String s);
    //辅助函数，在索赔单中，根据一个字段，查询出这个字段等于某一个值或者多个字的数据，值需要用’/‘隔开，用在查询int格式上
    @DS("newMscLowCodeFormal")
    @Select("select * from warranty_claims where deleteSign=1 and ${filedName}=#{parseInt}")
    List<warrantyClaimsPojo> inquiryWarrantyClaimOneFiledInt(String filedName, int parseInt);
    //辅助函数：调取所有的不良品信息
    @DS("newMscLowCodeFormal")
    @Select("select * from bhgpczdzb")
    List<noGoodPartAssPojo> inquiryNoGoodPartAll();
    //辅助函数：向后端的不合格品库中写入代码，需要写入多个字段
    @DS("newMscLowCodeFormal")
    @Update("update bhgpczdzb set ${s}=#{s1} where id=#{id}")
    void editNoGoodDataOneField(String id, String s, String s1);
    //辅助函数：修改索赔单中的int类型的数据
    @DS("newMscLowCodeFormal")
    @Update("update warranty_claims set ${s}=#{parseInt} where id=#{id}")
    void editWarrantyClaimOneFieldInt(Integer id, String s, int parseInt);
    //辅助函数：查询零公里所有的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from zero_kilometers_data where deleteSign=1")
    List<zeroKilometersPojo> inquiryZeroKilometersAll();
    //辅助函数，对零公里的清单中，插入一行数据
    @DS("newMscLowCodeFormal")
    @Insert("INSERT INTO zero_kilometers_data SET " +
            "establishTime = #{establishTime}, " +
            "updateTime = #{updateTime}, " +
            "deleteSign = #{deleteSign}, " +
            "editName = #{editName}, " +
            "occurDate = #{occurDate}, " +
            "engineType = #{engineType}, " +
            "engineNo = #{engineNo}, " +
            "describeUse = #{describeUse}, " +
            "quantity = #{quantity}, " +
            "detailed = #{detailed}, " +
            "placeProduction = #{placeProduction}, " +
            "responsibleParty = #{responsibleParty}, " +
            "isExam = #{isExam}," +
            "typeUse=#{typeUse}," +
            "partName=#{partName}," +
            "problemType=#{problemType}," +
            "problemId=#{problemId}," +
            "mileage=#{mileage}")
    void inertZeroKilometersOne(zeroKilometersPojo pojo);
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），根据一个字段，查询等于该字段的所有数据,是字符串的
    @DS("newMscLowCodeFormal")
    @Select("select * from zero_kilometers_data where ${fieldName}=#{fieldVal} and deleteSign=1")
    List<zeroKilometersPojo> inquiryOneFieldZeroKilometers(String fieldName,String fieldVal);
    //修改一个过程清单的一个字段，是字符串类型
    @DS("newMscLowCodeFormal")
    @Update("update zero_kilometers_data set ${s}=#{s1} where id=#{id}")
    void editZeroKilometersField(Integer id, String s, String s1);
    //修改一个过程清单的一个字段，是字符串类型
    @DS("newMscLowCodeFormal")
    @Update("update zero_kilometers_data set ${s}=#{parseInt} where id=#{id}")
    void editZeroKilometersFieldInt(Integer id, String s, int parseInt);
    //辅助函数：对不良品库中，根据一个字段，查询这个字段等于某一值，可以等于多个值，每个值中间有‘/’隔开；配的是类型；
    @DS("newMscLowCodeFormal")
    @Select("select * from bhgpczdzb where ${filedName}=#{s} and sys_deleted=0")
    List<noGoodPartAssPojo> inquiryNoGoodFiledSeveral(String filedName, String s);
    //辅助函数：向后端IPTV报告中筛选数据，可以实现筛选多个等段同时等于多个数值，最多可以为10个。
    @DS("newMscLowCodeFormal")
    @Select("select * from iptv_report_data where ${filedName1}=#{filedVal1} and deleteSign=1")
    List<iptvReportDataPojo> inquiryIptvReportField1(String filedName1, String filedVal1);
    @DS("newMscLowCodeFormal")
    @Select("select * from iptv_report_data where ${filedName1}=#{filedVal1} and ${filedName2}=#{filedVal2} and deleteSign=1")
    List<iptvReportDataPojo> inquiryIptvReportField2(String filedName1, String filedVal1,String filedName2, String filedVal2);
    @DS("newMscLowCodeFormal")
    @Select("select * from iptv_report_data where ${filedName1}=#{filedVal1} and ${filedName2}=#{filedVal2} and ${filedName3}=#{filedVal3} and deleteSign=1")
    List<iptvReportDataPojo> inquiryIptvReportField3(String filedName1, String filedVal1,String filedName2, String filedVal2,String filedName3, String filedVal3);
    @DS("newMscLowCodeFormal")
    @Select("select * from iptv_report_data where ${filedName1}=#{filedVal1} and ${filedName2}=#{filedVal2} and ${filedName3}=#{filedVal3}  and ${filedName4}=#{filedVal4} and deleteSign=1")
    List<iptvReportDataPojo> inquiryIptvReportField4(String filedName1, String filedVal1,String filedName2, String filedVal2,String filedName3, String filedVal3,String filedName4, String filedVal4);
    //插入一行IPTV报告，所有的字段都插入
    @DS("newMscLowCodeFormal")
    @Insert("insert iptv_report_data (" +
            "editName, indicatorType, yearData, " +
            "moonDate, engineType, targetName, " +
            "yearTargetVal, moonNumber, moonSample, " +
            "moonTargetVal, moonAchieve, addUpTargetVal, " +
            "addUpAchieve, moonAchieveRatio, yearAchieveRatio, " +
            "isAchieve, achieveTrend, examNumb, " +
            "information, deleteSign, establishTime, " +
            "updateTime)" +
            " VALUES (" +
            "#{editName}, #{indicatorType}, #{yearData}, " +
            "#{moonDate}, #{engineType}, #{targetName}, " +
            "#{yearTargetVal}, #{moonNumber}, #{moonSample}, " +
            "#{moonTargetVal}, #{moonAchieve}, #{addUpTargetVal}, " +
            "#{addUpAchieve}, #{moonAchieveRatio}, #{yearAchieveRatio}, " +
            "#{isAchieve}, #{achieveTrend}, #{examNumb}, " +
            "#{information}, #{deleteSign}, #{establishTime}, " +
            "#{updateTime})")
    void insertOneIptvReport(iptvReportDataPojo pojo);
    //根据id，修改IptvReport中所有的数据
    @DS("newMscLowCodeFormal")
    @Update("UPDATE iptv_report_data SET " +
            "establishTime = #{establishTime}, " +
            "updateTime = #{updateTime}, " +
            "deleteSign = #{deleteSign}, " +
            "editName = #{editName}, " +
            "indicatorType = #{indicatorType}, " +
            "yearData = #{yearData}, " +
            "moonDate = #{moonDate}, " +
            "engineType = #{engineType}, " +
            "targetName = #{targetName}, " +
            "yearTargetVal = #{yearTargetVal}, " +
            "moonNumber = #{moonNumber}, " +
            "moonSample = #{moonSample}, " +
            "moonTargetVal = #{moonTargetVal}, " +
            "moonAchieve = #{moonAchieve}, " +
            "addUpTargetVal = #{addUpTargetVal}, " +
            "addUpAchieve = #{addUpAchieve}, " +
            "moonAchieveRatio = #{moonAchieveRatio}, " +
            "yearAchieveRatio = #{yearAchieveRatio}, " +
            "isAchieve = #{isAchieve}, " +
            "achieveTrend = #{achieveTrend}, " +
            "examNumb = #{examNumb}, " +
            "information = #{information} " +
            "WHERE id = #{id}")
    void editOneLineIptvReport(iptvReportDataPojo pojo);
    //辅助函数：向后端IPTV报告中查询所有的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from iptv_report_data where deleteSign=1")
    List<iptvReportDataPojo> inquiryIptvReportAll();
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），修改一行所有的数据
    @DS("newMscLowCodeFormal")
    @Update("UPDATE zero_kilometers_data " +
            "SET " +
            "  establishTime = #{establishTime}, " +
            "  updateTime = #{updateTime}, " +
            "  deleteSign = #{deleteSign}, " +
            "  editName = #{editName}, " +
            "  occurDate = #{occurDate}, " +
            "  engineType = #{engineType}, " +
            "  engineNo = #{engineNo}, " +
            "  describeUse = #{describeUse}, " +
            "  quantity = #{quantity}, " +
            "  detailed = #{detailed}, " +
            "  placeProduction = #{placeProduction}, " +
            "  responsibleParty = #{responsibleParty}, " +
            "  isExam = #{isExam}, " +
            "  typeUse = #{typeUse}, " +
            "  partName = #{partName}, " +
            "  problemType = #{problemType}, " +
            "  problemId = #{problemId}, " +
            "  mileage = #{mileage} " +
            "WHERE id = #{id}")
    void editZeroKilometersOneAllById(zeroKilometersPojo pojo);
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），根据一个字段，查询等于该字段的所有数据,是整数型的，主要用于int
    @DS("newMscLowCodeFormal")
    @Select("select * from zero_kilometers_data where ${fieldName}=#{fieldVal}")
    List<zeroKilometersPojo> inquiryOneFieldZeroKilometersInt(String fieldName, Integer fieldVal);
    //辅助函数，在索赔单中，根据一个字段，查询这个字段的一个范围,用在查询字符串类型的，主要用在了查询文本格式保存的时间上

    @DS("newMscLowCodeFormal")
    @Select("select * from warranty_claims where ${filedName}>=#{minVal} and ${filedName}<#{maxVal}")
    List<warrantyClaimsPojo> inquiryWarrantyClaimOneFiledScope(String filedName, String minVal, String maxVal);
}
